<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<div role="main" class="main">
	<div class="center">
		<c:choose>
			<c:when test="${ exception != null}"> 
				<div class="row margintop200">

					<div class="span6 offset3">
						<div class="alert alert-danger">
							<strong>Erreur!</strong> ${exception }
						</div>
					</div>

				</div>
			</c:when>
			<c:otherwise>
		<div class="row aligncenter">
			<div class="span11">
				<h2 class="left">Liste des modes de paiement</h2>
				<div class="conteneur-tableau">
					<table class="table table-bordered table-striped bg-bleu">
						<thead>
							<tr class="header">
								<th>Mode de Paiement</th>
								<th>Accessible client classique </th>
								<th>Accessible super client</th>
							</tr>
						</thead>
						<tbody id="modeDePaiement-table">
						<c:forEach items="${modes}" var="mode">
								<tr id="${mode.id}">
									<td>${mode.libelle}</td>
									<td><div class="chkboxpaiement"><input id="accesClient-${mode.id}" type="checkbox" <c:if test="${mode.accesClient}">checked </c:if> ></div></td>
									<td><div class="chkboxpaiement"><input id="accesSuperClient-${mode.id}" type="checkbox" <c:if test="${mode.accesSuperClient}">checked</c:if> ></div></td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
				</div>
				<div></div>
			</div>
		</div>
		<div class="row margintop20 hide" id="divSuccess">
						<div class="span6 offset3">
							<div class="alert alert-success">
							<strong>Succès!</strong>
							Accessibilités bien mises à jour !
							</div>
						</div>
		</div>
		<div class="row margintop20">
			<div class="span4 offset4">
				<span class="btn btn-success" id="valider" > <i
					class="icon-ok icon-white"></i> Valider
				</span>
			</div>
		</div>


	<script>
$(document).ready(function() {
	$('#valider').click(function()
	{
		$("#divSuccess").addClass("hide");
	if (confirm("Etes-vous certain de vouloir mettre à jour ces accessibilités ?"))
				        {
							var parent = $('#modeDePaiement-table');
							var childs = parent.children();
							var data = "";
							for (i = 0; i < childs.length; i++)
							{
								if(i==0)
								{
									var id = $(childs[i]).attr('id');
									data="form="+id+"/"+$('#accesClient-'+id).is(':checked')+"/"+$('#accesSuperClient-'+id).is(':checked');
								}
								else
								{
									var id = $(childs[i]).attr('id');
									data= data + "-"+id+"/"+$('#accesClient-'+id).is(':checked')+"/"+$('#accesSuperClient-'+id).is(':checked');
								}
							}
				            $.ajax(
				            {
				                   type: "POST",
				                   url: "<%= request.getContextPath() %>/updateModeDePaiement.do",
				                   data: data,
				                   cache: false,
			 
				                   success: function()
			                   {
				                	   $("#divSuccess").removeClass("hide");
				                    
				                   }
				             });
				        }
				    });
});
	</script>
	</c:otherwise>
		</c:choose>
</div>

</div>